@echo off
setlocal enabledelayedexpansion

echo ==========================================
echo Sokit CLI Linux Quick Build Script (Windows)
echo ==========================================

echo.
echo This script will help you build Linux version of sokit-cli on Windows
echo.

REM Check Docker
where docker >nul 2>&1
if %errorlevel% neq 0 (
    echo Error: Docker not found
    echo Please install Docker Desktop first: https://www.docker.com/products/docker-desktop/
    pause
    exit /b 1
)

echo Checking Docker service...
docker info >nul 2>&1
if %errorlevel% neq 0 (
    echo Error: Docker service not running
    echo Please start Docker Desktop
    pause
    exit /b 1
)

echo Docker check passed!
echo.

REM Select build method
echo Please select build method:
echo 1) Use Docker auto build (Recommended)
echo 2) Manual build instructions
echo 3) Exit

set /p choice="Enter your choice (1-3): "

if "%choice%"=="1" goto docker_build
if "%choice%"=="2" goto manual_build
if "%choice%"=="3" goto exit
goto invalid_choice

:docker_build
echo.
echo Starting Docker build...
echo.

REM Check if docker_build.sh exists
if not exist "docker_build.sh" (
    echo Error: docker_build.sh script not found
    echo Please ensure you are running this script from project root directory
    pause
    exit /b 1
)

REM Run Docker build
echo Starting Docker build...
echo Note: First run may take longer to download Docker images
echo.

REM Use WSL or Git Bash to run shell script
where bash >nul 2>&1
if %errorlevel% equ 0 (
    bash docker_build.sh
) else (
    echo Bash not found, trying WSL...
    wsl bash docker_build.sh
)

if %errorlevel% equ 0 (
    echo.
    echo ==========================================
    echo Build completed!
    echo ==========================================
    echo Build results located at: docker-output/
    echo.
    if exist "docker-output" (
        echo Generated files:
        dir docker-output
    )
) else (
    echo.
    echo Build failed, please check error messages
)

pause
exit /b 0

:manual_build
echo.
echo ==========================================
echo Manual Build Instructions
echo ==========================================
echo.
echo To build sokit-cli in Linux environment, follow these steps:
echo.
echo 1. Prepare Linux environment:
echo    - Ubuntu/Debian: sudo apt install cmake g++ make git qt6-base-dev qt6-tools-dev
echo    - CentOS/RHEL: sudo yum install cmake gcc-c++ make git qt6-qtbase-devel qt6-qttools-devel
echo    - Arch Linux: sudo pacman -S cmake gcc make git qt6-base qt6-tools
echo.
echo 2. Clone project:
echo    git clone https://github.com/sinpolib/sokit.git
echo    cd sokit
echo.
echo 3. Run build script:
echo    chmod +x build_linux_package.sh
echo    ./build_linux_package.sh
echo.
echo 4. Build results:
echo    - Executable: build-cli/bin/sokit-cli
echo    - Package: sokit-cli-linux-*.tar.gz
echo.
echo For detailed instructions, see: LINUX_BUILD_GUIDE.md
echo.
pause
exit /b 0

:invalid_choice
echo Invalid choice, please run script again
pause
exit /b 1

:exit
echo Exiting build script
pause
exit /b 0 